package com.example.mvvmapplication.api

import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

/**
 *
 * @ClassName:      SunOfBeachShopApi$
 * @Description:    api接口实现
 * @Author:         xinya
 * @CreateDate:     2020/11/3$ 16:44$
 * @UpdateRemark:   更新内容
 * @Version:        1.0
 */
class SunOfBeachShopApi {
    companion object {
        val instance by lazy {
            SunOfBeachShopApi()
        }
    }

    private val httpLoggingInterceptor = HttpLoggingInterceptor()

    init {
        httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
    }

    private val okHttpClient = OkHttpClient.Builder()
        .callTimeout(30, TimeUnit.SECONDS)
        .addInterceptor(httpLoggingInterceptor)
        .build()

    private val retrofit = Retrofit.Builder()
        .baseUrl(ISunOfBeachShopService.BASE_URL)
        .addConverterFactory(GsonConverterFactory.create())
        .client(okHttpClient)
        .build()

    val sunOfBeachShopApiService: ISunOfBeachShopService = retrofit.create(ISunOfBeachShopService::class.java)

}